package com.hqq.concurrency.producer_consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Consumer
 * 消费者
 * Created by heqianqian on 2017/8/1.
 */
public class Consumer {
    private static final Logger LOGGER = LoggerFactory.getLogger(Consumer.class);

    private final ItemQueue queue;

    private final String name;

    public Consumer(String name, ItemQueue queue) {
        this.name = name;
        this.queue = queue;
    }

    /**
     * Consume item from the queue
     */
    public void consume() throws InterruptedException {

        Item item = queue.take();
        LOGGER.info("Consumer [{}] consume item [{}] produced by [{}]", name, item.getId(), item.getProducer());

    }
}
